//
//  HomeToolBarView.swift
//  Weibo
//
//  Created by 郑克哥哥 on 2017/7/29.
//  Copyright © 2017年 郑克哥哥. All rights reserved.
//

import UIKit

class HomeToolBarView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //添加 控件设置约束
    private func setupUI() {
        
        let retweetBut = addChildButton(imageName: "timeline_icon_retweet" , title: "转发")
        let commentBut = addChildButton(imageName: "timeline_icon_comment", title: "评论")
        let unlikeBut = addChildButton(imageName: "timeline_icon_unlike", title: "赞")
        
        //添加约束
        retweetBut.snp.makeConstraints { (make) in
            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(commentBut)
        }
        commentBut.snp.makeConstraints { (make) in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetBut.snp.trailing)
            make.width.equalTo(unlikeBut)
        }
        unlikeBut.snp.makeConstraints { (make) in
            make.top.trailing.bottom.equalTo(self)
            
            make.leading.equalTo(commentBut.snp.trailing)
            
        }
        
        let lineView_one = addLineView()
        
        let lineView_tow = addLineView()
        
        lineView_one.snp.makeConstraints { (make) in
            make.centerX.equalTo(retweetBut.snp.trailing)
            make.centerY.equalTo(retweetBut)
        }
        lineView_tow.snp.makeConstraints { (make) in
            make.centerX.equalTo(commentBut.snp.trailing)
            make.centerY.equalTo(commentBut)
        }
    }
    
    //添加竖线视图
    private func addLineView()->UIImageView{
        
        let lineImgView = UIImageView(image:UIImage(named: "timeline_card_bottom_line"))
        addSubview(lineImgView)
        return lineImgView
    }
    
    //添加子按钮
    private func addChildButton(imageName:String,title:String)->UIButton{
        
        let button = UIButton()
        //设置背景图片
        button.setBackgroundImage(UIImage(named:"timeline_card_bottom_background"), for: .normal)
        button.setImage(UIImage(named:imageName), for: .normal)
        button.setTitle(title, for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        addSubview(button)
        return button
    }

}
